app.controller 'BlogListController', [
	'$scope', 'Blog', 'blogList', '$location'
	, ($scope, Blog,  blogList,  $location)->
		$scope.blogListClass = 'active'
		$scope.blogList = blogList
		$scope.detailView = (blog)->
			$location.path '/blog/detail/'+blog.id
]

app.controller 'BlogDetailController', [
	'$scope', 'Blog', 'blog', '$timeout', '$alert', '$location'
	, ($scope, Blog, blog, $timeout, $alert, $location)->
		$scope.blogListClass = 'active'
		$scope.blog = blog
]

app.config [ '$routeProvider', ($routeProvider)->
	$routeProvider.when '/blog/list',
		templateUrl : '/main/tmpl/blog_list'
		controller: 'BlogListController'
		resolve: 
			blogList: (Blog)->
				Blog.query()

	$routeProvider.when '/blog/detail/:id',
		templateUrl : '/main/tmpl/blog_detail'
		controller : 'BlogDetailController'
		resolve: 
			blog: (Blog, $route)->
				Blog.get {id: $route.current.params.id}
	$routeProvider.when '/blog',
		redirectTo : '/blog/list'
]
